<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class SendEmailJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * 任务最大尝试次数。
     */
    public $tries = 5;

    /**
     * 无任务的时候睡眠时间。
     */
    public $sleep = 60;

    /**
     * 任务运行的超时时间。
     */
    public $timeout = 120;

    protected $param;

    /**
     * SendEmailJob constructor.
     * @param $param
     */
    public function __construct($param)
    {
        $this->param = $param;
    }

    /**
     *
     */
    public function handle()
    {
        foreach ($this->param as $e) {
            \Mail::to($e['email'])->send($e['mail']);
        }
    }

    /**
     * 要处理的失败任务。
     */
    public function failed(Exception $exception)
    {
        Log::info('邮件发送失败 ' . $this->param);
    }
}
